#+TITLE: Disassembly
#+AUTHOR: Zelphir Kaltstahl
#+EMAIL: zelphirkaltstahl@posteo.de
#+STARTUP: content indent align inlineimages hideblocks entitiesplain nologdone nologreschedule nologredeadline nologrefile
#+TODO: TODO INPROGRESS | DONE
#+DATE: [2021-10-29 Fri]
#+LANGUAGE: English
#+PRIORITIES: A E E

* Disassembly

You can look at the disassembled GNU Guile virtual machine instructions, which a program translates into using the following commands:

#+begin_src sh
guild compile my-guile-file.scm
guild compile my-compiled-guile-file.go
#+end_src

For example the following script:

#+begin_src scheme
(define (plus1 a b)
  (+ a b))

(define plus2
  (λ (a b)
    (+ a b)))
#+end_src

Might give the following disassembly:

#+begin_src text
Disassembly of <unnamed function> at #xe8:

   0    (instrument-entry 16354)                              at example-program-for-disassembly.scm:4:0
   2    (assert-nargs-ee/locals 1 2)    ;; 3 slots (0 args)
   3    (call-scm<-thread 2 62)                               at example-program-for-disassembly.scm:1:0
   5    (static-ref 1 16329)            ;; plus1
   7    (call-scm<-scm-scm 1 2 1 41)
   9    (make-non-immediate 0 16327)    ;; #<procedure plus1 (a b)>
  11    (scm-set!/immediate 1 1 0)
  12    (static-ref 1 16336)            ;; plus2              at example-program-for-disassembly.scm:4:0
  14    (call-scm<-scm-scm 2 2 1 41)
  16    (make-non-immediate 1 16334)    ;; #<procedure plus2 (a b)>
  18    (scm-set!/immediate 2 1 1)
  19    (make-immediate 2 2052)         ;; #<unspecified>
  20    (reset-frame 1)                 ;; 1 slot
  21    (handle-interrupts)
  22    (return-values)


Disassembly of plus1 at #x144:

   0    (instrument-entry 16337)                              at example-program-for-disassembly.scm:1:0
   2    (assert-nargs-ee/locals 3 0)    ;; 3 slots (2 args)
   3    (call-scm<-scm-scm 2 1 0 0)                           at example-program-for-disassembly.scm:2:2
   5    (reset-frame 1)                 ;; 1 slot
   6    (handle-interrupts)
   7    (return-values)


Disassembly of plus2 at #x164:

   0    (instrument-entry 16335)                              at example-program-for-disassembly.scm:5:2
   2    (assert-nargs-ee/locals 3 0)    ;; 3 slots (2 args)
   3    (call-scm<-scm-scm 2 1 0 0)                           at example-program-for-disassembly.scm:6:4
   5    (reset-frame 1)                 ;; 1 slot
   6    (handle-interrupts)
   7    (return-values)


Disassembly of <unnamed function> at #x184:

   0    (instrument-entry 16333)                              at example-program-for-disassembly.scm:6:4
   2    (assert-nargs-ee/locals 1 1)    ;; 2 slots (0 args)
   3    (static-patch! 16286 28)
   6    (make-non-immediate 1 16281)    ;; "plus1"
   8    (call-scm<-scm 1 1 14)
  10    (static-set! 1 16285)           ;; plus1
  12    (static-patch! 16287 -28)
  15    (static-patch! 16288 22)
  18    (make-non-immediate 1 16283)    ;; "plus2"
  20    (call-scm<-scm 1 1 14)
  22    (static-set! 1 16287)           ;; plus2
  24    (static-patch! 16289 -32)
  27    (reset-frame 1)                 ;; 1 slot
  28    (make-immediate 0 2052)         ;; #<unspecified>
  29    (return-values)
#+end_src
